<!-- daterange picker -->
<link rel="stylesheet" href="__PUBLIC__/AdminLTE/plugins/daterangepicker/daterangepicker.css">
<div class="content-wrapper">
    <section class="content-header">
        <h1>订单审批</h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">订单管理</li>
            <li class="active">订单审批</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
                <form class="form-inline" action="/admin/approval/approvalPendingOrderList" method="get">
                    <div class="form-group">
                        <label for="name">客户名称 </label>
                        <input type="text" class="form-control" id="name" name="name" placeholder="客户名称" value="{$name}">
                    </div>
                    <div class="form-group">
                        <label for="department_id" class="control-label">部门 </label>
                        <select id="department_id" class="form-control" name="department_id">
                            <option value="0">请选择</option>
                            <foreach name="departmentList" item="department">
                                <option value="{$department.department_id}" <if condition="$department.department_id eq $department_id ">selected</if>>{$department.name}</option>
                            </foreach>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-info" id="save-btn">查询</button>
                </form>
            </div>
            <div class="box-body table-responsive">
                <table class="table table-bordered">
                    <tbody>
                    <tr>
                        <th style="width: 80px">ID</th>
                        <th>订单ID</th>
                        <th>客户名称</th>
                        <th>推广产品</th>
                        <th>联系人</th>
                        <th>下单时间</th>
                        <th>订单金额</th>
                        <th>部门</th>
                        <th>部门人员</th>
                        <th>状态</th>
                        <th style="width: 150px">操作</th>
                    </tr>
                    <if condition="count($orderList) eq 0"><tr><td class="text-center" colspan="12">暂无数据...</td></tr></if>
                    <foreach name="orderList" item="order">
                        <tr>
                            <td>{$order.order_id}</td>
                            <td>{$order.order_code}</td>
                            <td>{$order.company_name}</td>
                            <td>{$order.product_name}</td>
                            <td>{$order.name}</td>
                            <td>{$order.create_time}</td>
                            <td>{$order.amount}</td>
                            <td>{$order.department_name}</td>
                            <td>{$order.admin_name}</td>
                            <td><p>{$order.status_desc}</p>
                                <if condition="$order.status eq 35 ">
                                        <if condition="$order.dp_manager_review eq 1 ">
                                                <span class="label label-success">已通过</span>
                                            <else />
                                                <span class="label label-danger">已拒绝</span>
                                        </if>
                                    <elseif condition="$order.status eq 40 " />
                                        <if condition="$order.director_review eq 1 ">
                                            <span class="label label-success">已通过</span>
                                            <else />
                                            <span class="label label-danger">已拒绝</span>
                                        </if>
                                    <elseif condition="$order.status eq 45 " />
                                        <if condition="$order.g_manager_review eq 1 ">
                                            <span class="label label-success">已通过</span>
                                            <else />
                                            <span class="label label-danger">已拒绝</span>
                                        </if>
                                </if>
                            </td>
                            <td style="width: 180px">
                                <button class="btn btn-primary btn-xs" type="button" onclick="window.location.href='/admin/approval/orderDetail?id={$order.order_id}'">详情</button>&nbsp;
								<!--<php>if($order['status']<55){</php>-->
                                <button class="btn btn-success btn-xs btn-pass" type="button" data-id ="{$order.order_id}">通过</button>&nbsp;
                                <button class="btn btn-warning btn-xs btn-show-modal" type="button" data-toggle="modal" data-target="#gridSystemModal" data-id ="{$order.order_id}">拒绝</button>&nbsp;
								<!--<php>}</php>-->
                                <button class="btn bg-aqua-active btn-xs show-log" type="button" data-id="{$order.order_id}">日志</button>&nbsp;
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            </div>
            <div class="box-footer clearfix">{$page_html}</div>
        </div>
    </section>
</div>
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel" id="gridSystemModal">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">审核</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="javascript:;" method="post">
                    <div class="form-group">
                        <input type="hidden" id="order_id" name="order_id" value="">
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-2" for="reason">拒绝原因</label>
                        <div class="col-sm-10">
                            <textarea id="reason" class="form-control" name="reason" rows="6" placeholder="拒绝原因"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-refuse">确定</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!--modal2-->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModal2Label">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModal2Label">订单操作日志</h4>
            </div>

            <div class="modal-body">

                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">日志列表</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body no-padding">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th style="width: 10px">#</th>
                                <th>操作详情</th>
                                <th style="width: 60px">操作人</th>
                                <th style="width: 150px">操作时间</th>
                            </tr>
                            </thead>
                            <tbody id="order-log-list">
                            <tr>
                                <td>1.</td>
                                <td>Update software</td>
                                <td>
                                    <div class="progress progress-xs">
                                        <div class="progress-bar progress-bar-danger" style="width: 55%"></div>
                                    </div>
                                </td>
                                <td><span class="badge bg-red">55%</span></td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/AdminLTE/plugins/layer/layer.js"></script>
<script type="application/javascript">
    $(function () {
        $(".btn-show-modal").click(function () {
            var order_id = $(this).attr('data-id');
            $("#order_id").val(order_id);
        });
        //通过
        $(".btn-pass").click(function () {
            var order_id = $(this).attr('data-id');
            layer.confirm('确认审核通过吗？',function () {
                $.post('/admin/approval/ajaxApprovalOrder',{
                    order_id: order_id,
                    type:'pass'
                },function (data) {
                    if(data.Code == 999) {
                        layer.alert('操作成功', {
                            skin: 'layui-layer-molv' //样式类名
                            ,closeBtn: 0
                        }, function(){
                            window.location.href = '/admin/approval/orderList';
                        });
                    } else {
                        layer.alert(data.Msg, {
                            skin: 'layui-layer-molv' //样式类名
                            ,closeBtn: 0
                        });
                    }
                },"JSON");
            });
        });
        //拒绝
        $(".btn-refuse").click(function () {
            var order_id = $("#order_id").val();
            var reason = $("#reason").val();
            if(!reason || reason==''){
                layer.msg('请填写拒绝原因',{
                    time:1000
                });
                $("#reason").focus();
                return false;
            }
            $('#gridSystemModal').modal('hide');
            $.post('/admin/approval/ajaxApprovalOrder',{
                order_id: order_id,
                type:'refuse',
                description:reason
            },function (data) {
                if(data.Code == 999) {
                    layer.alert('操作成功', {
                        skin: 'layui-layer-molv' //样式类名
                        ,closeBtn: 0
                    }, function(){
                        window.location.href = '/admin/approval/orderList';
                    });
                } else {
                    layer.alert(data.Msg, {
                        skin: 'layui-layer-molv' //样式类名
                        ,closeBtn: 0
                    });
                }
            },"JSON");
        });
        //日志层
        $(".show-log").click(function () {
            var id = $(this).attr('data-id');
            console.log(id);
            if(id=='' || isNaN(id)){
                layer.msg('参数异常',{time:2000});
                return false;
            }
            $.post('/admin/order/ajaxGetOrderLogList',{
                id:id
            },function (_data) {
                var logList = _data.Data.all;
                var str = "";
                if(_data.Code==999){
                    logList.forEach(function (item,i) {
                        str += "<tr>";
                        str += "<td>"+(i+1)+"</td>";
                        str += "<td>"+item.description+"</td>";
                        str += "<td>"+item.admin_name+"</td>";
                        str += "<td>"+item.add_time+"</td>";
                        str += "</tr>";
                    })
                }else{
                    layer.msg(_data.Msg,{time:2000});
                    return false;
                }
                $("#order-log-list").empty().html(str);
                $("#myModal2").modal('show');
            },"JSON");

        });
    });
</script>